package com.xxcloud.service.folder.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import com.xxcloud.common.utils.DateTimeUtil;
import com.xxcloud.dao.dto.xxcloud.Folder;
import com.xxcloud.model.web.folder.dto.FolderDTO;
import com.xxcloud.model.web.folder.vo.FolderVO;

/**
 * Created by chenbingwen on 19/10/28.
 */
public abstract class AbstractFolderService {

    protected List<FolderVO> convert2FolderVOS(List<Folder> folders) {
        if (CollectionUtils.isEmpty(folders)) {
            return Collections.emptyList();
        }
        List<FolderVO> result = new ArrayList<>();
        folders.stream().forEach(folder -> {
            FolderVO folderVO = new FolderVO();
            BeanUtils.copyProperties(folder, folderVO);
            folderVO.setCreateTime(DateTimeUtil.date2Long(folder.getCreateTime()));
            folderVO.setUpdateTime(DateTimeUtil.date2Long(folder.getUpdateTime()));
            result.add(folderVO);
        });
        return result;
    }

    protected Folder convert2Folder(FolderDTO dto) {
        Folder folder = new Folder();
        folder.setId(dto.getId());
        folder.setParentId(dto.getParentId());
        folder.setName(dto.getName());
        return folder;
    }
}
